import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:myapp/api/Http.dart';
import 'package:myapp/api/Urls.dart';
import 'package:myapp/model/GoodsDetailModel.dart';
import 'package:myapp/page/GoodDetailPage.dart';
import 'package:myapp/page/home/SearchResultPage.dart';

import 'IGenericDataProvider.dart';

class PageUtil {
  static toGoodsDetailPage(context, searchId, goodsId) {
    Map<String, String> paraMap = Map();
    paraMap["goods_id_list"] = [goodsId.toString()].toString();
    paraMap["search_id"] = searchId.toString();
    DioUtils.postHttp(Urls.GoodDetailUrl, parameters: paraMap,
        onSuccess: (data) {
      GoodsDetailModel goodsDetailModel =
          GoodsDetailModel.fromMap(jsonDecode(data));
      goodsDetailModel.goodsDetailResponse.goodsDetails[0].searchId = searchId;
      //item点击事件
      Navigator.push(
          context,
          MaterialPageRoute(
              builder: (context) => IGenericDataProvider<GoodsDetailModel>(
                    child: GoodsDetailPage(),
                    data: goodsDetailModel,
                  )));
    }, onError: (err) {
      print(err);
    });
  }

  static toSearchResultPage(context, query) {
    Map<String, String> paraMap = Map();
    //item点击事件
    Navigator.pushReplacement(
      context,
      MaterialPageRoute(
          builder: (context) => IGenericDataProvider<String>(
                child: SearchResultPage(),
                data: query,
              )),
    );
  }
}
